package com.wangsb;

import java.util.Scanner;
import java.util.function.IntFunction;

/**
 * @Description: TODO
 * @author: shenbing.wang@hand-china
 * @date: 2021年05月23日 17:09
 */

public class FirstQuestion {
    /*
    1. 编程题
    提示用户输入年月日信息，判断这一天是这一年中的第几天并打印。
     */
    public static void main(String[] args) {
        int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        Scanner scanner = new Scanner(System.in);
        boolean isExit = false;
        //操作错误
        int errorCount = 0;
        int year;
        int nextInt = 0;
        //设置防沉迷系统
        int count = 0;
        do {
            if (count == 0) {
                System.out.println("===================欢迎来到你说日期我来我来告诉你是本年度的多少天小游戏========");
                System.out.println("1、开始                    2、退出");
                nextInt = scanner.nextInt();
            }
            if (nextInt == 1) {

                if (count > 4) {
                    System.out.println("count = " + count);
                    System.out.println("防止沉迷系统已开启，你今日游戏"+count+"次数已使用完毕");
                    break;
                }
                System.out.println("请输入年份：");
                year = scanner.nextInt();
                boolean yearFinallyFlag = HomeWorkUtils.isRunYear(year);
                if (yearFinallyFlag) {
                    days[1] = 29;
                }
                while (year < 1) {
                    System.out.println("您输入的年份不合法，请重新输入：");
                    year = scanner.nextInt();
                }
                System.out.println("请输入月份：");
                int month = scanner.nextInt();
                while (month > 12 || month < 1) {
                    System.out.println("请输入合法的月份：");
                    month = scanner.nextInt();
                }
                System.out.println("请输入日期：");
                int day = scanner.nextInt();
                while (day > days[month - 1]) {
                    System.out.println("您输入的日期不合法请重新输入");
                    day = scanner.nextInt();
                }
                int result = day;
                result = HomeWorkUtils.getResult(days, month, result);
                System.out.println(year + "年" + month + "月" + day + "日是一年当中的第" + result + "天");
                count++;
                System.out.println("是否继续游戏Y/N");
                String next = scanner.next();
                if ("y".equalsIgnoreCase(next)) {
                    isExit = true;
                } else if ("N".equalsIgnoreCase(next)) {
                    System.out.println("您已退出游戏！欢迎下次再玩");
                    break;
                } else {
                    while (!"y".equalsIgnoreCase(next) && !"N".equalsIgnoreCase(next)) {
                        System.out.println("您的输入有误请重新输入：");
                        next = scanner.next();
                        errorCount++;
                        if (errorCount == 3) {
                            System.out.println("您的输入有误次數超过：" + errorCount + "次,已为您退出游戏");
                            break;
                        }
                    }
                    if ("N".equalsIgnoreCase(next)) {
                        System.out.println("游戏结束！");
                        break;
                    } else if ("y".equalsIgnoreCase(next)) {
                        isExit = true;
                    }
                }
            } else if (nextInt == 2) {
                System.out.println("退出！");
                break;
            } else {
                while (nextInt != 1 && nextInt != 2) {
                    System.out.println("您的输入有误请重新输入：");
                    nextInt = scanner.nextInt();
                    errorCount++;
                    if (errorCount == 3) {
                        System.out.println("您的输入有误次數超过：" + errorCount + "次,已为您退出游戏");
                        break;
                    }
                }
                if (nextInt == 2) {
                    System.out.println("游戏结束！");
                    break;
                }
                if (nextInt == 1) {
                    isExit = true;

                }
            }

        } while (isExit);
    }
}